package com.jjpro.controller.user;

import com.jjpro.annotation.SystemControllerLog;
import com.jjpro.controller.BaseController;
import com.jjpro.entity.lock.VerificationCodeRequest;
import com.jjpro.entity.user.LoginOutRequest;
import com.jjpro.entity.user.LoginRequest;
import com.jjpro.entity.user.RegisterRequest;
import com.jjpro.requestservice.UserInofRequestService;
import com.jjpro.utils.AppletResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;


@RestController
@RequestMapping
public class UserController extends BaseController {

    @Autowired
    private UserInofRequestService userInofRequestService;

    @SystemControllerLog(funcionExplain = "发送短信验证码")
    @PostMapping(value = "/user/verificationCode")
    public AppletResult getVerificationCode(HttpServletRequest request,
                                            @RequestBody VerificationCodeRequest verificationCodeRequest){
        verificationCodeRequest = (VerificationCodeRequest) headUtil.getAllReqHead(request,verificationCodeRequest);
        return userInofRequestService.getVerificationCode(verificationCodeRequest);
    }

    @SystemControllerLog(funcionExplain = "用户注册")
    @PostMapping(value = "/user/register")
    public AppletResult register(HttpServletRequest request,
                                 @RequestBody RegisterRequest registerRequest){
        registerRequest = (RegisterRequest) headUtil.getAllReqHead(request,registerRequest);
        return userInofRequestService.register(registerRequest);
    }

    @SystemControllerLog(funcionExplain = "用户登陆")
    @PostMapping(value = "/user/login")
    public AppletResult login(HttpServletRequest request,
                              @RequestBody LoginRequest loginRequest){
        loginRequest = (LoginRequest) headUtil.getAllReqHead(request,loginRequest);
        return userInofRequestService.login(loginRequest);
    }

    @SystemControllerLog(funcionExplain = "用户退出登陆")
    @PostMapping(value = "/user/loginOut")
    public AppletResult loginOut(HttpServletRequest request,
                                 @RequestBody LoginOutRequest loginOutRequest){
        loginOutRequest = (LoginOutRequest) headUtil.getAllReqHead(request,loginOutRequest);
        return userInofRequestService.loginOut(loginOutRequest);
    }
}
